library(tableone)
library(survival)
#分类变量转换
dput(names(mimic_sad_aki))#获取变量名
#纳入变量定义（排除ID及不需要的变量）
myvars <- c("age", "weight", "gender", "temperature", "heart_rate", "resp_rate", 
            "spo2", "sbp", "dbp", "mbp", "wbc", "hemoglobin", "platelet", 
            "bun", "cr", "glu", "Na", "Cl", "K", "Mg", "Ca", "P", "inr", 
            "pt", "ptt", "bicarbonate", "aniongap", "gcs", "vent", "crrt", 
            "vaso", "seda", "sofa_score", "ami", "ckd", "copd", "hyperte", 
            "dm", "sad", "aki", "stroke", "hosp_mort", "icustay", "hospstay", 
            "deliriumtime", "sepsistime", "icu28dmort", "icustay_d", "hospstay_d")
#分类变量定义
catvars <- c("gender", "vent", "crrt", "vaso", "seda", "ami", "ckd", "copd", "hyperte", 
             "dm", "sad", "stroke", "hosp_mort", "icu28dmort")
#分组汇总+偏态数据使用中位数表示
tab1 <- CreateTableOne(vars = myvars,strata = "sad",data = mimic_sad_aki,factorVars = catvars)
tableone_01 <- print(tab1,nonnormal = TRUE,quote = FALSE,noSpaces = TRUE,printToggle = FALSE)
write.csv(tableone_01,file="tableone_01.csv")